﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using KPIS.GERP.Models.HRM;

namespace KPIS.GERP.Models.SYS
{
    [DataContract, Table("SysApprovePathDtl")]
    public class ApprovePathDtl
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity), DataMember, Display(Name = "ApprovePathId", ResourceType = typeof (Resources.ApprovePathResource))]
        public virtual int AppPathDtlId { get; set; }

        [DataMember, Display(Name = "ApproverType", ResourceType = typeof (Resources.ApprovePathResource))]
        public virtual ApproverType ApproverType { get; set; }

        [DataMember]
        public virtual bool IsExecPosEmployeesOnlyInSameJobSitePath { get; set; }

        [DataMember]
        public virtual bool IsApproveAble { get; set; }

        [DataMember]
        public virtual bool IsForwardable { get; set; }

        [DataMember]
        public virtual bool IsRejectable { get; set; }

        [DataMember]
        public virtual bool IsPendable { get; set; }

        [DataMember]
        public virtual bool IsSendBackable { get; set; }

        [DataMember]
        public virtual bool IsLockable { get; set; }

        [DataMember]
        public virtual bool IsTakebackAble { get; set; }

        [DataMember, Display(Name = "AmountMin", ResourceType = typeof (Resources.ApprovePathResource))]
        public virtual decimal? AmountMin { get; set; }

        [DataMember, Display(Name = "AmountMax", ResourceType = typeof (Resources.ApprovePathResource))]
        public virtual decimal? AmountMax { get; set; }

        [DataMember, ForeignKey("ApprovePath")]
        public virtual int? AppPathId { get; set; }

        [DataMember, ForeignKey("ApproveProcess")]
        public virtual int? AppPrcId { get; set; }

        [DataMember, ForeignKey("ExecPosGroup"), Display(Name = "ExecPosGroupId", ResourceType = typeof (Resources.ApprovePathResource))]
        public int? ExecPosGroupId { get; set; }

        [DataMember, ForeignKey("Position"), Display(Name = "PosId", ResourceType = typeof (Resources.ApprovePathResource))]
        public virtual int? PosId { get; set; }

        [DataMember]
        public virtual ExecPosGroup ExecPosGroup { get; set; }

        [DataMember]
        public virtual Position Position { get; set; }

        [DataMember]
        public virtual ApproveProcess ApproveProcess { get; set; }

        [DataMember]
        public virtual ApprovePath ApprovePath { get; set; }

        [DataMember, Display(Name = "CreatedBy", ResourceType = typeof (Resources.ExecPosGroupResource))]
        public virtual int? CreatedBy { get; set; }

        [DataMember, Display(Name = "CreatedWhen", ResourceType = typeof (Resources.ExecPosGroupResource))]
        public virtual DateTime CreatedWhen { get; set; }

        [DataMember, Display(Name = "UpdatedBy", ResourceType = typeof (Resources.ExecPosGroupResource))]
        public virtual int? UpdatedBy { get; set; }

        [DataMember, Display(Name = "UpdatedWhen", ResourceType = typeof (Resources.ExecPosGroupResource))]
        public virtual DateTime? UpdatedWhen { get; set; }

        public virtual bool IsPassAmountCondition(decimal? requestAmount)
        {
            if (requestAmount == null && AmountMin != null && AmountMin > 0)
                return false;
            requestAmount = requestAmount ?? 0;

            return AmountMax != null && requestAmount.Value <= AmountMax.Value;
        }
    }
}